<template>
    <div>
        <div class="header_box">
            <ul>
                <li>登录</li>
                <li>退出登录</li>
                <li>我的订单</li>
                <li>会员中心</li>
                <li>帮助中心</li>
                <li>关于我们</li>
                <li>手机版</li>
            </ul>
        </div>
        <div class="nav_box">
            <div class="nav_content">
                <div class="logo_box">
                    <img src="../assets/img/logo.png" />
                </div>
                <!--  -->
                <ul>
                    <li class="active">首页</li>
                    <li v-for="item in categoryList" :key="item.id" @click.prevent="ToCategory(item.id)">
                        {{ item.name }}
                        <!-- 移入二级导航 -->
                        <div class="hover_box">
                            <div class="items" v-for="items in item.children" :key="items.id"
                                @click.stop="GoTowPage(items.id)">
                                <img :src="items.picture" alt="">
                                <p>{{ items.name }}</p>
                            </div>
                        </div>
                    </li>
                </ul>
                <!--  -->
                <div class="search_box">
                    <i class="el-icon-search"></i>
                    <el-input v-model="text" size="small" placeholder="搜一搜"></el-input>
                    <i class="el-icon-shopping-cart-1"></i>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
export default {
  name: "HeadView",
  data() {
    return {
      text: "",
      isShow: false,
      categoryList: [],
      categoryChildrenList: [],
    };
  },
  created() {
    this.$nextTick(() => {
      this.$api.categoryList().then((res) => {
        //console.log(res.data.result);
        this.categoryList = res.data.result;
      });
    });
  },
  methods: {
    //点击导航通过id请求数据
    ToCategory(val) {
      this.$router.push({ name: "category", query: { oneId: val } });
      console.log("id", val);
    },
    //二级导航跳转
    GoTowPage(val) {
      this.$router.push({ name: 'navItem', query: { towId: val } })
      // html 取参  $route.query.id
      // script 取参  this.$route.query.id
      console.log("二级id", val);
    },
  },
};
</script>

<style lang="scss" scoped>
.header_box {
  width: 100%;
  height: 50px;
  background: #333333;

  ul {
    width: 1240px;
    height: 100%;
    margin: 0 auto;
    display: flex;
    justify-content: right;
    align-items: center;

    li {
      color: #cdcdc3;
      font-size: 14px;
      padding: 0 12px;
      border-right: 1px solid rgb(136, 130, 130);
    }

    li:last-child {
      border: none;
    }
  }
}
.nav_box {
  width: 100%;
  height: 130px;
  background: white;
  position: relative;
  .nav_content {
    width: 1240px;
    height: 100%;
    margin: 0 auto;
    display: flex;

    .logo_box {
      width: 200px;
      height: 130px;

      img {
        width: 100%;
        margin-top: 20px;
      }
    }

    ul {
      width: 820px;
      height: 130px;
      display: flex;
      align-items: center;
      justify-content: space-around;

      li {
        font-size: 16px;
        padding: 0 20px;
      }
      li:hover {
        color: #27bb9a;
      }
    }
    ul {
      width: 820px;
      height: 130px;
      display: flex;
      align-items: center;
      justify-content: space-around;

      li {
        font-size: 16px;
        padding: 0 20px;
      }

      li:hover {
        height: 130px;
        line-height: 130px;
      }

      li:hover .hover_box {
        height: 130px;
        transition: 0.6s;
        display: block;
        box-shadow: 0px 0px 3px 1.5px rgb(194, 192, 192);
        align-items: center;
        z-index: 10;
      }
    }

    .search_box {
      display: flex;
      align-items: center;

      .el-input {
        border: none;
        margin: 0 10px;
      }

      .el-icon-shopping-cart-1 {
        font-size: 24px;
      }
    }
  }
}

.hover_box {
  width: 1240px;
  height: 0px;
  background: white;
  position: absolute;
  top: 100px;
  left: 233.5px;
  display: none;
  display: flex;
  overflow: hidden;

  .items {
    width: 120px;
    height: 100px;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    float: left;
    margin-top: 10px;

    img {
      width: 80px;
      height: 60px;
    }

    p {
      font-size: 16px;
      line-height: 40px;
    }
  }
}

.active {
  color: #3bba9b;
  text-decoration: underline;
}
</style>